package main.java.controller;

import main.java.dao.AppointmentDao;
import main.java.dao.DepartmentDao;
import main.java.dao.DoctorDao;
import main.java.dao.impl.AppointmentDaoImpl;
import main.java.dao.impl.DepartmentDaoImpl;
import main.java.dao.impl.DoctorDaoImpl;
import main.java.polo.Appointment;
import main.java.polo.Department;
import main.java.polo.Doctor;

import java.util.List;
import java.util.Scanner;

public class AppointmentController {
    /**
     * 查询所有医生
     */
    public static void selectDoctor() {
        DepartmentDao departmentDao = new DepartmentDaoImpl();
        List<Department> departmentList = departmentDao.selectAll();
        for (Department department : departmentList) {
            System.out.println(department);
        }
        System.out.println("请输入科室编号");
        Scanner scanner = new Scanner(System.in);
        String deptId = scanner.next();
        DoctorDao doctorDao = new DoctorDaoImpl();
        List<Doctor> doctorList = doctorDao.selectByDept(deptId);
        for (Doctor doctor : doctorList) {
            System.out.println(doctor);
        }
    }

    /**
     * 预约
     * @return 预约成功返回1，失败返回0
     */
    public static int insert() {
        AppointmentDao appointmentDao = new AppointmentDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入患者姓名，医生姓名，预约时间（年月日时）");
        String studentName = scanner.next();
        String doctorName = scanner.next();
        String appointmentTime = scanner.next();
        Appointment appointment = new Appointment(null, studentName, doctorName, appointmentTime,null);
        return appointmentDao.insert(appointment);
    }

    /**
     * 根据预约人学号查询预约信息
     */
    public static void selectRecord() {
        AppointmentDao appointmentDao = new AppointmentDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入预约人姓名");
        String studentName = scanner.next();
        List<Appointment> appointmentList = appointmentDao.selectByName(studentName);
        for (Appointment appointment : appointmentList) {
            System.out.println(appointment);
        }
    }

    /**
     * 删除预约信息
     * @return 删除成功返回1，失败返回0
     */
    public static int delete() {
        AppointmentDao appointmentDao = new AppointmentDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入预约编号");
        int apId = scanner.nextInt();
        return appointmentDao.delete(apId);
    }
}
